home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / 4thcmp21.zip / EXEC.4TH < prev    next >
Text File  |  1993-06-23  |  2KB  |  74 lines

  1. \ DOS EXECUTE LIBRARY
  2. \ Contents Copyright (C) 1991 by Thomas Almy
  3. \ Revised 3/93 by Tom Almy
  4.  
  5. \ Permission is granted to registered users of ForthCMP to sell or distribute
  6. \ computer programs incorporating the compiled contents of this file.
  7.  
  8. \ This file should be loaded at the start of the program. The
  9. \ STRINGS library must be loaded, and loaded before this file.
  10.  
  11. .( Loading EXEC) CR
  12. 10 HEX
  13. DSEG
  14. CREATE xpb 0E ALLOT 
  15. 0 xpb ! -1 xpb 6 + ! -1 xpb 8 + ! -1 xpb 0A + ! -1 xpb 0C + !
  16. CSEG
  17. CREATE ssav 0 , 0 , 
  18. DSEG
  19.  
  20. \ the code for exec could be optimized based on SEPSSEG? and SEPDSEG?
  21. \ either or both being off, but it would not make that much difference
  22. \ in code size.
  23.  
  24. \ code 9C is PUSHF, 9D is POPF
  25.  
  26. 1 1 IN/OUT 
  27. CODE exec ( ^ASCIIZCommand -- failFlag )
  28.     BP PUSH CSEG 9C C, DS PUSHSEG
  29.     AX DX MOV
  30.     CS: ssav 2+ [] SS <SEG  SP CS: ssav [] MOV    
  31.     AX DS <SEG  AX ES >SEG
  32.     4B00 # AX MOV
  33.     xpb # BX MOV
  34.     21 INT
  35.     CS: ssav 2+ [] SS >SEG
  36.     CS: ssav [] SP MOV
  37.     DS POPSEG 9D C, BP POP 
  38.     <U ~ IF, AX AX XOR THEN, RET
  39. END-CODE
  40.  
  41. DSEG
  42. CREATE crChr 3 ALLOT
  43.   0D crChr C!    \ crChr 1 is string consisting of CR only
  44.   20 crChr 1+ C! \ while crChr 1+ 1 is string consisting of BL only
  45.   0 crChr 2+ C!  \ and crChr 2+ is counted zero length string
  46.  
  47. 2 1 IN/OUT
  48. : spawn ( ^command ^args -- failFlag )
  49.      crChr 1+ 1  ROT COUNT STRCAT
  50.      crChr 1 STRCAT STRPCK -1 OVER +!
  51.      xpb 2+ ! ?DS: xpb 4 + !
  52.      ASCIIZ exec
  53. ;  
  54.  
  55. 1 0 IN/OUT
  56. SEPDSEG? #IF
  57. : EXEC
  58.      " COMSPEC" STR>DSEG getenv ?DUP IF
  59.      SWAP DUP C@ IF \ program to run
  60.           " /C " STR>DSEG COUNT ROT COUNT STRCAT STRPCK
  61.      ELSE DROP  crChr 2+ THEN
  62.      spawn DROP
  63.      ELSE  ." No COMSPEC" BYE THEN ;
  64. #ELSE
  65. : EXEC
  66.      " COMSPEC" getenv ?DUP IF
  67.      SWAP DUP C@ IF \ program to run
  68.           CNT" /C " ROT COUNT STRCAT STRPCK
  69.      ELSE DROP crChr 2+ THEN
  70.      spawn DROP
  71.      ELSE  ." No COMSPEC" BYE THEN ;
  72. #THEN
  73. 0A = #IF DECIMAL #THEN
  74.